home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / Thread Manager / ThreadUtilities / Util Headers & Source / ThreadUtil.p < prev    next >
Encoding:
Text File  |  1994-11-17  |  4.6 KB  |  135 lines  |  [TEXT/MPS ]

  1. {
  2.     File:        ThreadUtil.p
  3.  
  4.     Contains:    External Interface to Thread Manager Utilities
  5.  
  6.     Written by:    Brad Post, Eric Anderson and Bill Knott
  7.  
  8.     Copyright:    © 1993 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.                 
  12.                 4/19/93        bsp        Added the busy : Boolean into the LinkedList model
  13.                 3/3/93        bsp        Added the lastInList element to the LinkedListSemaphore model.
  14.                 2/12/93        whk        Converted Interfaces.
  15.                 1/31/93        ewa        New Today.
  16.  
  17. }
  18.  
  19. {$IFC UNDEFINED UsingIncludes}
  20. {$SETC UsingIncludes := 0}
  21. {$ENDC}
  22.  
  23. {$IFC NOT UsingIncludes}
  24.     UNIT ThreadUtil;
  25.     INTERFACE
  26. {$ENDC}
  27.  
  28. {$IFC UNDEFINED UsingThreadUtil}
  29. {$SETC UsingThreadUtil := 1}
  30.  
  31. {$I+}
  32. {$SETC ThreadUtilIncludes := UsingIncludes}
  33. {$SETC UsingIncludes := 1}
  34. {$IFC UNDEFINED UsingTimer}
  35. {$I $$Shell(PInterfaces)Timer.p}
  36. {$ENDC}
  37. {$IFC UNDEFINED UsingThreads}
  38. {$I $$Shell(PInterfaces)Threads.p}
  39. {$ENDC}
  40. {$SETC UsingIncludes := ThreadUtilIncludes}
  41.  
  42. { Constant Definitions }
  43.  
  44. {--------------------------------------------------------------------------------}
  45. { Here are some of the error codes that can be returned.                          }
  46. {--------------------------------------------------------------------------------}
  47.  
  48. CONST
  49.     semaphoreButtHeadErr     = 1;
  50.     semaphoreWaitErr        = 2;
  51.  
  52. TYPE
  53. {--------------------------------------------------------------------------------}
  54. { These typedefs are used only by the SimpleSemaphore model.                        }
  55. {--------------------------------------------------------------------------------}
  56.  
  57.     SimpleSemaphorePtr    = ^SimpleSemaphore;
  58.     SimpleSemaphore        = BOOLEAN;
  59.  
  60. {--------------------------------------------------------------------------------}
  61. { These typedefs and structs are used only by the LinkedList Semaphore model.    }
  62. {--------------------------------------------------------------------------------}
  63.  
  64.     LinkedListElementPtr = ^LinkedListElement;
  65.     LinkedListElement = RECORD
  66.         whoAmI        : ThreadID;
  67.         next        : LinkedListElementPtr;
  68.     END;
  69.  
  70.  
  71.     LinkedListSemaphorePtr = ^LinkedListSemaphore;
  72.     LinkedListSemaphore = RECORD
  73.         available        : Boolean;
  74.         busy            : Boolean;
  75.         theHolder        : ThreadID;
  76.         waitingList        : LinkedListElementPtr;
  77.         lastInList        : LinkedListElementPtr;
  78.     END;
  79.  
  80. {--------------------------------------------------------------------------------}
  81. { These typedefs and structs are only used by the Array Semaphore model.           }
  82. {--------------------------------------------------------------------------------}
  83.  
  84.     ArraySemaphorePtr = ^ArraySemaphore;
  85.     ArraySemaphore = RECORD
  86.         available        : Boolean;
  87.         theHolder        : ThreadID;
  88.         whoseNext        : LONGINT;
  89.         nextSpot        : LONGINT;
  90.         numberWaiting    : LONGINT;
  91.         maxInQueue        : LONGINT;
  92.         waitList        : ARRAY [0..0] OF ThreadID;
  93.     END;
  94.  
  95. { Routine Definitions }
  96.  
  97. {--------------------------------------------------------------------------------}
  98. { Routine prototypes.                                                                }
  99. {--------------------------------------------------------------------------------}
  100.  
  101. PROCEDURE DelayThread(millisecDelay    : LONGINT);
  102.  
  103. {--------------------------------------------------------------------------------}
  104. { These are the rountines for using Simple Semaphores.                             }
  105. {--------------------------------------------------------------------------------}
  106.  
  107. FUNCTION CreateSimpleSemaphore(VAR aSemaphore : SimpleSemaphorePtr) : OSErr;
  108. FUNCTION GetSimpleSemaphore(aSemaphore : SimpleSemaphorePtr) : OSErr;
  109. FUNCTION ReleaseSimpleSemaphore(aSemaphore : SimpleSemaphorePtr) : OSErr;
  110. FUNCTION DeleteSimpleSemaphore(aSemaphore : SimpleSemaphorePtr) : OSErr;
  111.  
  112. {--------------------------------------------------------------------------------}
  113. { These are the rountines for using LinkedList Semaphores.                         }
  114. {--------------------------------------------------------------------------------}
  115.  
  116. FUNCTION CreateLinkedListSemaphore(VAR aSemaphore : LinkedListSemaphorePtr) : OSErr;
  117. FUNCTION GetLinkedListSemaphore(VAR whichOne : LinkedListElement; aSemaphore : LinkedListSemaphorePtr) : OSErr;
  118. FUNCTION ReleaseLinkedListSemaphore(aSemaphore : LinkedListSemaphorePtr) : OSErr;
  119. FUNCTION DeleteLinkedListSemaphore(aSemaphore : LinkedListSemaphorePtr) : OSErr;
  120.  
  121. {--------------------------------------------------------------------------------}
  122. { These are the rountines for using Array Semaphores.                             }
  123. {--------------------------------------------------------------------------------}
  124.  
  125. FUNCTION CreateArraySemaphore(maxInQueue : LONGINT; VAR aSemaphore : ArraySemaphorePtr) : OSErr;
  126. FUNCTION GetArraySemaphore(aSemaphore : ArraySemaphorePtr) : OSErr;
  127. FUNCTION ReleaseArraySemaphore(aSemaphore : ArraySemaphorePtr) : OSErr;
  128. FUNCTION DeleteArraySemaphore(aSemaphore : ArraySemaphorePtr) : OSErr;
  129.  
  130. {$ENDC}    { UsingThreadUtil }
  131.  
  132. {$IFC NOT UsingIncludes}
  133.     END.
  134. {$ENDC}
  135.